package br.com.informatos.dialogs;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends FragmentActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);


		Button btn_progress = (Button)findViewById(R.id.show_progress);
		Button btn_alert = (Button)findViewById(R.id.show_dialog);
		Button btn_custom = (Button)findViewById(R.id.show_dialog_custom);

		btn_progress.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				DialogFragment dialog = AlertDialogFragment.newInstance();
				dialog.show(getSupportFragmentManager(), "progress");				
			}
		});


		btn_alert.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				DialogFragment dialog = AlertDialogFragment.newInstance();
				dialog.show(getSupportFragmentManager(), "alert");	

			}
		});


		btn_custom.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				DialogFragment dialog = AlertDialogFragment.newInstance();
				dialog.show(getSupportFragmentManager(), "custom");	

			}
		});

	}


	public static class AlertDialogFragment extends DialogFragment {
		public static AlertDialogFragment newInstance() {
			AlertDialogFragment frag = new AlertDialogFragment();
			return frag;

		}
		
		@Override
		public Dialog onCreateDialog(Bundle saveInstanceState){
			AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
			dialog.setTitle(getActivity().getString(R.string.attention));
			dialog.setMessage(getActivity().getString(R.string.button_gonna_press));
			dialog.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(R.string.yes), new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Toast.makeText(getActivity(), R.string.pressed_yes, Toast.LENGTH_SHORT).show();
					
				}
			});
			
			
			
			dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(R.string.pressed_no),
					new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					Toast.makeText(getActivity(), R.string.pressed_no, Toast.LENGTH_SHORT).show();
					
				}
			});
			
			
			
			return dialog;
		}
		
	}
	
	public static class ProgressDialogFragment extends DialogFragment {
		public static ProgressDialogFragment newInstance(){
			ProgressDialogFragment frag = new ProgressDialogFragment();
			return frag;
		}
		
		@Override
		public Dialog onCreateDialog(Bundle saveInstanceState){
			Dialog dialog = new ProgressDialog(getActivity());
			dialog.setTitle(R.string.wait);
			return dialog;
			
		}
		
	}
	
	public static class CustomDialogFragment extends DialogFragment{
		
		public static CustomDialogFragment newInstance(){
			CustomDialogFragment frag = new CustomDialogFragment();
			return frag;
		}
		
		@Override
		public void onCreate(Bundle savedInstanceState){
			super.onCreate(savedInstanceState);
			
		}
		
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savednstanceState){
			View v = inflater.inflate(R.layout.custom_dialog, container, false);
			getDialog().setTitle(R.string.k19_trainning);
			return v;
			
		}
	}
	

}
